<template>
    <a-modal v-model="visible" title="新增" @ok="handleOk">
        <a-form>
            <a-form-item
                label="职务编码"
                :label-col="formItemLayout.labelCol"
                :wrapper-col="formItemLayout.wrapperCol"
            >
                <a-input placeholder="" v-model="formData.positionSign"/>
            </a-form-item>
            <a-form-item
                    label="职务名称"
                    :label-col="formItemLayout.labelCol"
                    :wrapper-col="formItemLayout.wrapperCol"
            >
                <a-input placeholder="" v-model="formData.positionName"/>
            </a-form-item>
            <a-form-item
                    label="月基础积分"
                    :label-col="formItemLayout.labelCol"
                    :wrapper-col="formItemLayout.wrapperCol"
            >
                <a-input placeholder="" v-model="formData.baseIntegral"/>
            </a-form-item>
            <a-form-item
                label="每次互动积分"
                :label-col="formItemLayout.labelCol"
                :wrapper-col="formItemLayout.wrapperCol"
            >
                <a-input placeholder="" v-model="formData.signInScore"/>
            </a-form-item>
            <a-form-item
                label="每次签到积分"
                :label-col="formItemLayout.labelCol"
                :wrapper-col="formItemLayout.wrapperCol"
            >
                <a-input placeholder="" v-model="formData.interaction"/>
            </a-form-item>
        </a-form>
    </a-modal>
</template>
<script>
import API from "../api/api_cfg_position_integral"
export default {
    data() {
        return {
            formLayout: 'horizontal',
            visible: false,
            mode:'',
            formData: {}
        };
    },
    computed: {
        formItemLayout() {
            const { formLayout } = this;
            return formLayout === 'horizontal'
                ? {
                    labelCol: { span: 8 },
                    wrapperCol: { span: 16 },
                }
                : {};
        },
        buttonItemLayout() {
            const { formLayout } = this;
            return formLayout === 'horizontal'
                ? {
                    wrapperCol: { span: 8, offset: 16 },
                }
                : {};
        },
    },
    methods: {
        add() {
            this.mode = 'add';
            this.formData = {};
            this.visible = true;
        },
        update(row){
            this.mode = 'edit';
            this.formData = row;
            this.visible = true;
        },
        handleOk(e) {
            let that = this;
            let func = that.mode === 'add'? API.add: API.update;
            func(that.formData).then(res =>{
                if (res.code === 0){
                    that.$message.success('操作成功')
                    that.$emit('ok')
                }else {
                    that.$message.error(res.msg)
                }
            }).catch(e =>{
                that.$message.error('操作失败,请联系管理员')
            })

            that.visible = false;
        },
    },
};
</script>
